package com.fr.report.script.core.parser;

import com.fr.report.script.Primitive;
import com.fr.report.script.core.FArray;
import java.util.Arrays;

public abstract class BinaryExpression extends AbstractNode
{
  protected Object binaryOperation(Object paramObject1, Object paramObject2, String paramString)
    throws UtilEvalError
  {
    FArray localFArray;
    Object[] arrayOfObject;
    if (paramObject1 == null)
      paramObject1 = Primitive.NULL;
    if (paramObject2 == null)
      paramObject2 = Primitive.NULL;
    if ((paramObject1 == Primitive.ERROR_NAME) || (paramObject1 == Primitive.ERROR_VALUE) || (paramObject2 == Primitive.ERROR_NAME) || (paramObject2 == Primitive.ERROR_VALUE))
      return Primitive.ERROR_NAME;
    if ((paramObject1 == Primitive.NOFILTER) || (paramObject2 == Primitive.NOFILTER))
    {
      if (isRelationExpression())
        return Boolean.TRUE;
      return Primitive.NOFILTER;
    }
    if ((paramObject1 instanceof FArray) && (paramObject2 instanceof FArray))
      return arrayBinaryOperation((FArray)paramObject1, (FArray)paramObject2, paramString);
    if (paramObject1 instanceof FArray)
    {
      localFArray = (FArray)paramObject1;
      arrayOfObject = new Object[localFArray.length()];
      Arrays.fill(arrayOfObject, paramObject2);
      return arrayBinaryOperation(localFArray, new FArray(arrayOfObject), paramString);
    }
    if (paramObject2 instanceof FArray)
    {
      localFArray = (FArray)paramObject2;
      arrayOfObject = new Object[localFArray.length()];
      Arrays.fill(arrayOfObject, paramObject1);
      return arrayBinaryOperation(new FArray(arrayOfObject), localFArray, paramString);
    }
    return objectBinaryOperation(paramObject1, paramObject2, paramString);
  }

  protected boolean isRelationExpression()
  {
    return false;
  }

  protected Object arrayBinaryOperation(FArray paramFArray1, FArray paramFArray2, String paramString)
    throws UtilEvalError
  {
    int i = paramFArray1.length();
    int j = paramFArray2.length();
    int k = Math.min(i, j);
    int l = Math.max(i, j);
    Object[] arrayOfObject = new Object[l];
    for (int i1 = 0; i1 < k; ++i1)
      arrayOfObject[i1] = binaryOperation(paramFArray1.elementAt(i1), paramFArray2.elementAt(i1), paramString);
    FArray localFArray = (i == l) ? paramFArray1 : paramFArray2;
    for (int i2 = k; i2 < l; ++i2)
      arrayOfObject[i2] = localFArray.elementAt(i2);
    return new FArray(arrayOfObject);
  }

  protected abstract Object objectBinaryOperation(Object paramObject1, Object paramObject2, String paramString)
    throws UtilEvalError;
}